package library.and.xps.com.step.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhy.autolayout.AutoLinearLayout;

import library.and.xps.com.step.R;
import library.and.xps.com.step.m.model.ActiveDetailIntentParams;
import library.and.xps.com.step.m.model.TeamActiveList;
import library.and.xps.com.step.util.CommonUtils;
import library.and.xps.com.step.util.DateUtil;
import library.and.xps.com.step.view.activity.TeamActiveDetailActivity;

//团队活动列表
public class ChallengrListAdapter extends AbstractRecyclerAdapter<TeamActiveList.ListBean> {
    public static final String TeamActiveListAdapter = "TeamActiveListAdapter";

    public ChallengrListAdapter(Context context, RecyclerView recyclerView) {
        super(context, recyclerView);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType, boolean isItem) {
        View v = LayoutInflater.from(parent.getContext()).inflate(
                R.layout.active_list_item, parent, false);
        return new MyViewHolder(v);
    }

    @Override
    protected void onBindViewHolder(RecyclerView.ViewHolder holder, int position, boolean isItem) {
        MyViewHolder myViewHolder = (MyViewHolder) holder;
        final TeamActiveList.ListBean data = getItem(position);

        CommonUtils.setUpimg(context, myViewHolder.iv_active_cover, data.getMark(), false);

        myViewHolder.tv_taname.setText("活动:" + data.getTaname());
        myViewHolder.tv_tatime.setText("开始时间:" + DateUtil.retrofitDateString(data.getStarttime()));
        myViewHolder.tv_tamember.setText("参与人数:" + data.getPeople() + "人");
        myViewHolder.al_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(context, TeamActiveDetailActivity.class);
                ActiveDetailIntentParams activeDetailIntentParams = new ActiveDetailIntentParams();
                activeDetailIntentParams.setDescribe(data.getDescribe());
                activeDetailIntentParams.setEndtime(data.getEndtime());
                activeDetailIntentParams.setStarttime(data.getStarttime());
                activeDetailIntentParams.setActivityid(data.getActivityid());
                activeDetailIntentParams.setMark(data.getMark());
                activeDetailIntentParams.setPeople(data.getPeople());
                activeDetailIntentParams.setState(data.getState());
//                activeDetailIntentParams.setType(dataset.getType());
//                activeDetailIntentParams.setFormat(dataset.getFormat());
                activeDetailIntentParams.setTeamid(data.getTeamid());
                activeDetailIntentParams.setTaname(data.getTaname());
                activeDetailIntentParams.setExercise(data.getExercise());
                i.putExtra("active", activeDetailIntentParams);
                i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(i);
            }
        });


    }



    private static class MyViewHolder extends RecyclerView.ViewHolder {

        ImageView iv_active_cover;
        TextView tv_taname, tv_tatime, tv_tamember;
        AutoLinearLayout al_item;

        MyViewHolder(View itemView) {
            super(itemView);
            iv_active_cover = (ImageView) itemView.findViewById(R.id.iv_active_cover);
            tv_taname = (TextView) itemView.findViewById(R.id.tv_taname);
            tv_tatime = (TextView) itemView.findViewById(R.id.tv_tatime);
            tv_tamember = (TextView) itemView.findViewById(R.id.tv_tamember);
            al_item = (AutoLinearLayout) itemView.findViewById(R.id.al_item);
        }
    }
}
